﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Koonsoft.HYCRM.BLL;
using Koonsoft.HYCRM.Model.Enum;

public partial class Empolyee_EmpolyeeList : BasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
    }

    /// <summary>
    /// 行绑定事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            LinkButton LinkManagement = e.Row.FindControl("LinkManagement") as LinkButton;
            LinkButton linkCancel = e.Row.FindControl("linkCancel") as LinkButton;
            LinkButton linkContracts = e.Row.FindControl("linkContracts") as LinkButton;

            int status = Convert.ToInt32(e.Row.Cells[4].Text);
            EmpolyeeStatus pStatus = (EmpolyeeStatus)status;
            e.Row.Cells[4].Text = RemarkAttribute.GetEnumRemark(pStatus);


            switch (pStatus)
            {
                case EmpolyeeStatus.Create:
                    linkCancel.Visible = true;
                    LinkManagement.Visible = false;
                    linkContracts.Visible = true;
                    break;
                case EmpolyeeStatus.Cancel:
                    LinkManagement.Visible = false;
                    break;
            }
        }
    }

    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "LoginCondition")
        {
            Response.Redirect(
                      string.Format("~/LoginCondition/UserMonthLoginCondition.aspx?LoginName={0}&Time={1}",
                                    e.CommandArgument, DateTime.Now.ToString("yyyy-MM-1")));
        }
        else
        {

            int id = Convert.ToInt32(e.CommandArgument.ToString());

            switch (e.CommandName)
            {
                case "Cancel":
                    if (new EmpolyeeBLL().Cancel(id))
                    {
                        AlertMsg("操作成功");
                    }
                    else
                    {
                        AlertMsg("操作失败");
                    }
                    break;

                case "Management":
                    Response.Redirect(string.Format("~/Empolyee/EmpolyeeDetail.aspx?ID={0}", id));
                    break;

                case "Contracts":
                    Response.Redirect(string.Format("~/Empolyee/DistributionEmplyeeContract.aspx?ID={0}", id));
                    break;
                case "info":
                    Response.Redirect(string.Format("~/Empolyee/MyEmplyeeContract.aspx?ID={0}", id));
                    break;
            }
        }
    }

    protected void Button2_Click(object sender, EventArgs e)
    {
        GridView1.DataBind();
    }

 }